﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyCompany.MyProject.Model;

/// <summary>
/// 接口响应数据
/// </summary>
public class ApiResponse
{
    /// <summary>
    /// 状态码
    /// </summary>
    public int Status { get; set; } = 200;
    /// <summary>
    /// 消息内容
    /// </summary>
    public string Value { get; set; } = "";
    /// <summary>
    /// 返回的对象
    /// </summary>
    public MessageModel<string> MessageModel { get; set; } = new MessageModel<string>();
    /// <summary>
    /// 构造函数
    /// </summary>
    /// <param name="statusCode"></param>
    /// <param name="msg"></param>
    public ApiResponse(StatusCode statusCode,string? msg=null)
    {
        switch (statusCode)
        {
            case StatusCode.CODE401:
                Status = 401;
                Value = msg ?? "很抱歉，您无权限访问该接口，请确保已经登录！";
                break;
            case StatusCode.CODE403:
                Status = 403;
                Value = msg ?? "很抱歉，您的访问权限等级不够，联系管理员";
                break;
            case StatusCode.CODE404:
                Status = 404;
                Value = "资源不存在";
                break;
            case StatusCode.CODE500:
                Status = 500;
                Value = msg;
                break;
        }

        MessageModel = new MessageModel<string>()
        {
            status = Status,
            msg = Value!,
            success = statusCode == StatusCode.CODE200
        };
    }
}

/// <summary>
/// 返回的状态码
/// </summary>
public enum StatusCode
{
    /// <summary>
    /// 200成功
    /// </summary>
    CODE200,
    /// <summary>
    /// 401无权限
    /// </summary>
    CODE401,
    /// <summary>
    /// 权限不够
    /// </summary>
    CODE403,
    /// <summary>
    /// 资源不存在
    /// </summary>
    CODE404,
    /// <summary>
    /// 服务器异常
    /// </summary>
    CODE500
}